home *** CD-ROM | disk | FTP | other *** search
- Path: news.tu-chemnitz.de!news
- From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
- Newsgroups: comp.lang.c
- Subject: Re: about free()
- Date: 28 Feb 96 10:07:43 GMT
- Organization: University of Technology Chemnitz, FRG
- Message-ID: <4h19na$3vh@pyrrhus-f.hrz.tu-chemnitz.de>
- References: <31333454.167E@mashie.ece.jhu.edu>
- NNTP-Posting-Host: sisyphus.hrz.tu-chemnitz.de
-
- Chenyang Xu <chenyang@mashie.ece.jhu.edu> writes:
-
- >Hi, there,
-
- > I have a simple question here.
-
- > I have a function say newarrary() which mallocs an array inside and
- >returns a pointer to this arrary. In another function foo.c, the result
- >of newarray() is assigned to a pointer ptr. Now after some operations on
- >this array. I use free(ptr) to free the memory allocated by newarrary().
- >My question is whould this cause a problem, since free() is not freeing
- >the same pointer which is allocated by the malloc() although this
- >pointer point to the same memory.
-
- ptr = malloc( king_size );
- other_ptr = ptr;
-
- then
- if( ptr != NULL ) free( ptr );
- is the same as
- if( other_ptr != NULL ) free( other_ptr );
-
- The function foo() is called by value as all c-functions.
- This means, it gets the value of its argument to process
- which is the same for ptr and other_ptr.
-
- hope that helps
-
- h.f.s.
-
- --
- Hans Friedrich Steffani
- Institut fuer Elektrische Maschinen und Antriebe
- TU Chemnitz-Zwickau
- e-mail: hans.steffani@e-technik.tu-chemnitz.de
-